﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.Job;
using CE.User;
using CE.Mail;

using TDS.Mail;

public partial class job_submit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session[GlobalSettings.CaptchaImageText] = GlobalSettings.GenerateRandomCode(4);
            hidSecurityCheck.Value = Session[GlobalSettings.CaptchaImageText].ToString();

            divAppForm.Visible = true;
            divMessage.Visible = false;

            usrDOB.StartYear = DateTime.Now.Year - 60;
            usrDOB.EndYear = DateTime.Now.Year - 15;
            //if (MobileDeviceUtil.isMobileBrowser())
            //{
            //    spanCV.Visible = false;
            //    spanFCV.Visible = false;
            //    rfvSummary.Enabled = true;
            //    revSummary.Enabled = true;
            //}
            //else
            //{
            //    //spanSummary.Visible = false;
            //    //spanSummaryArea.Visible = false;
            //    rfvSummary.Enabled = false;
            //    revSummary.Enabled = false;
            //}

            if (Request.Params["jid"] != null)
            {
                lblFormTitle.Text = "Job Application Form";

                int _jid = int.Parse(Request.Params["jid"].ToString());
                JobDB _jobdb = new JobDB();
                Job _job = _jobdb.GetJobByID(_jid);
                lblFormSubTitle.Text = "<a href='job-details-pop.aspx?jid=" + _job.JobID.ToString() + "'  class='opt2'>" + _job.JobTitle + "</a>";
                //lblJobRefCode.Text = "MY201208280001";
                ddlCountry.SelectedValue = _job.Country;
                ddlCountry.Enabled = false;
            }
            else
            {
                lblFormTitle.Text = "Send Us Your Resume";
                lblFormSubTitle.Text = "Deposit your CV into our talent bank";
            }

            //rfvCV.Enabled = false;
            if (Request.Params["say"] != null)
            {
                if (Request.Params["say"].ToString() == "thankyou")
                {
                    divAppForm.Visible = false;
                    divMessage.Visible = true;
                    lblMessage.ForeColor = System.Drawing.Color.Green;
                    lblMessage.Text = "Thanks! We have recevied your application. We will contact you if you are shortlisted. \nCheck you email to verify your Teledirect.com.sg account now.";
                    //Page.RegisterStartupScript("JS_CompletedJobAppAlert", "alert('Thank you very much.\nOnline form was sent successfully.\nWe will reply back to you soon.');");
                    ClientScript.RegisterStartupScript(this.GetType(), "JS_CompletedJobAppAlert", "alert('" + lblMessage.Text + "');", true);
                }
                else if (Request.Params["say"].ToString() == "exthankyou")
                {
                    divAppForm.Visible = false;
                    divMessage.Visible = true;
                    lblMessage.ForeColor = System.Drawing.Color.Green;
                    lblMessage.Text = "Thanks! We have recevied your application. We will contact you if you are shortlisted. \nCheck you applied application <a href='../user/application.aspx'>HERE</a>.";
                    //Page.RegisterStartupScript("JS_CompletedJobAppAlert", "alert('Thank you very much.\nOnline form was sent successfully.\nWe will reply back to you soon.');");
                    ClientScript.RegisterStartupScript(this.GetType(), "JS_CompletedJobAppAlert", "alert('" + lblMessage.Text + "');", true);
                }
            }

            if (Session[CE.Global.General.UserId] != null)
            {
                liLogin.Visible = false;
                liProfile.Visible = true;
                liApplication.Visible = true;
                liLogout.Visible = true;
                liChangePass.Visible = true;
            }

            if (Session[CE.Global.General.UserId] != null)
            {
                Int64 _uid = Int64.Parse(Session[CE.Global.General.UserId].ToString());
                Account _account = new Account();
                AccountDB _accountdb = new AccountDB();
                _account = _accountdb.GetAccount(_uid);

                Profile _userprofile = new Profile();
                ProfileDB _userprofiledb = new ProfileDB();
                _userprofile = _userprofiledb.GetProfile(_uid);

                ddlTitle.SelectedValue = _userprofile.Salutation;
                txtFullName.Text = _userprofile.Name;
                txtContactNumber.Text = _userprofile.ContactNumber;
                usrDOB.Day = _userprofile.DOB.Day;
                usrDOB.Month = _userprofile.DOB.Month;
                usrDOB.Year = _userprofile.DOB.Year;
                txtQualification.Text = _userprofile.Qualification;
                ddlExpYear.SelectedValue = _userprofile.YearsExperience;
                ddlSaleExp.SelectedValue = _userprofile.SalesExperience;
                ddlEmpStatus.SelectedValue = _userprofile.EmploymentStatus;
                txtOccupation.Text = _userprofile.Occupation;
                txtEmailAddress.Text = _account.Email;
                txtEmailAddress.Enabled = false;

                lblCV.Visible = true;
                //if (_userprofile.AttachCV != "")
                //{
                //    string[] filename = _userprofile.AttachCV.Split('\\');

                //    lblCV.Text = "Use <a href='../user/download.aspx?file=" + filename[filename.Length - 1] + "' target='_blank'>current CV</a> <span style='font-size:70%'>(or upload a new CV)</span>";
                //}

                rfvCV.Enabled = false;

                if (_userprofile.VoiceRecord != "")
                {
                    aRecord.HRef += "?file=" + _userprofile.VoiceRecord;
                }
            }

        }
    }


    protected void btnSubmitForm_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            if (Session[CE.Global.General.UserId] != null)
            {
                Int64 _uid = Int64.Parse(Session[CE.Global.General.UserId].ToString());
                Int64 _jid = Int64.Parse(Request.Params["jid"].ToString());

                Account _account = new Account();
                AccountDB _accountdb = new AccountDB();
                _account = _accountdb.GetAccount(_uid);

                Profile _userprofile = new Profile();
                ProfileDB _userprofiledb = new ProfileDB();
                _userprofile = _userprofiledb.GetProfile(_uid);

                Application _application = new Application();
                ApplicationDB _applicationdb = new ApplicationDB();

                long _result = -1;

                string _uploadFilePath = _userprofile.AttachCV;
                if (fupCV.HasFile)
                {
                    /***delete old cv***/
                    if (System.IO.File.Exists(_userprofile.AttachCV))
                        System.IO.File.Delete(_userprofile.AttachCV);

                    UploadFile(out _uploadFilePath, _uid);
                }

                _userprofile.Salutation = ddlTitle.SelectedItem.Text;
                _userprofile.Name = Server.HtmlEncode(txtFullName.Text.Trim());
                _userprofile.ContactNumber = Server.HtmlEncode(txtContactNumber.Text.Trim());
                _userprofile.DOB = usrDOB.GetDate();
                _userprofile.Qualification = Server.HtmlEncode(txtQualification.Text.Trim());
                _userprofile.YearsExperience = ddlExpYear.SelectedItem.Text;
                _userprofile.SalesExperience = ddlSaleExp.SelectedItem.Text;
                _userprofile.EmploymentStatus = ddlEmpStatus.SelectedItem.Text;
                _userprofile.Occupation = txtOccupation.Text;
                _userprofile.PreferredCountry = ddlCountry.SelectedValue;
                _userprofile.AttachCV = _uploadFilePath;

                if (Session["ConfirmLastFileName"] != null)
                {
                    string _tempFilePath = Session["ConfirmLastFileName"].ToString();
                    Session["ConfirmLastFileName"] = null;

                    string _webUrl = string.Empty;
                    string _filePath = GetFilePath(out _webUrl);
                    string _guidString = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 8);
                    string _fileName = "Voice_user" + _uid.ToString() + "_" + _guidString + ".wav";
                    if (_userprofile.VoiceRecord != "")
                    {
                        string[] _splitfilename = _userprofile.VoiceRecord.Split('\\');
                        _fileName = _splitfilename[_splitfilename.Length - 1];
                    }

                    string fileName = _filePath + _fileName;

                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }
                    System.IO.File.Move(_tempFilePath, fileName);

                    _userprofile.VoiceRecord = fileName;
                }

                _result = _userprofiledb.Insert(_userprofile);

                if (_result > 0)
                {
                    _application.Comments = Server.HtmlEncode(txtSummary.Text);
                    _application.RefUserID = _userprofile.RefUserId;
                    _application.RefJobID = _jid;
                    _application.ApplicationStatus = "pending";
                    _result = _applicationdb.InsertUpdate(_application);

                    if (_result > 0)
                    {
                        Response.Redirect("job-submit.aspx?say=exthankyou");
                    }
                }
            }
            else
            {
                Account _account = new Account();
                AccountDB _accountdb = new AccountDB();
                if (_accountdb.IsAlreadyExist(txtEmailAddress.Text))
                {
                    int _jid = 0;
                    if (Request.Params["jid"] != null)
                    {
                        _jid = int.Parse(Request.Params["jid"].ToString());
                    }
                    //email already existed
                    divMessage.Visible = true;
                    lblMessage.Text = "Email already registered. Click <a href='../user/login.aspx?jid=" + _jid.ToString() + "'>HERE</a> to login.";
                    lblMessage.Font.Bold = true;
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Focus();
                }
                else
                {
                    try
                    {
                        if (txtSecurityCheck.Text.Trim().ToUpper() == hidSecurityCheck.Value.ToUpper())
                        {
                            Int64 _jid = 0;
                            if (Request.Params["jid"] != null)
                            {
                                _jid = Int64.Parse(Request.Params["jid"].ToString());
                            }

                            Account _useraccount = new Account();
                            AccountDB _useraccountdb = new AccountDB();

                            Profile _userprofile = new Profile();
                            ProfileDB _userprofiledb = new ProfileDB();

                            Application _application = new Application();
                            ApplicationDB _applicationdb = new ApplicationDB();

                            long _result = -1;

                            _useraccount.Email = txtEmailAddress.Text;

                            Random _random = new Random();
                            string _authcode = "";
                            //Sakthi on 21 Jan 2011
                            //_authcode = "C" + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString();
                            _authcode = _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString() + _random.Next(9).ToString();

                            _useraccount.AuthCode = _authcode;

                            _useraccount.UserId = "USERAUTOIDCI";
                            _useraccount.UserTypeId = Convert.ToInt32(CE.Global.CEUserType.Customer);
                            _useraccount.IsAcceptTC = true;
                            _useraccount.Status = false;
                            _result = _useraccountdb.Insert(_useraccount);
                            _useraccount.UID = _result;

                            if (_result > 0)
                            {
                                string _uploadFilePath = string.Empty;
                                UploadFile(out _uploadFilePath, _result);

                                _userprofile.Salutation = ddlTitle.SelectedItem.Text;
                                _userprofile.Name = Server.HtmlEncode(txtFullName.Text.Trim());
                                _userprofile.ContactNumber = Server.HtmlEncode(txtContactNumber.Text.Trim());
                                _userprofile.DOB = usrDOB.GetDate();
                                _userprofile.Qualification = Server.HtmlEncode(txtQualification.Text.Trim());
                                _userprofile.YearsExperience = ddlExpYear.SelectedItem.Text;
                                _userprofile.SalesExperience = ddlSaleExp.SelectedItem.Text;
                                _userprofile.EmploymentStatus = ddlEmpStatus.SelectedItem.Text;
                                _userprofile.Occupation = txtOccupation.Text;
                                _userprofile.PreferredCountry = ddlCountry.SelectedValue;
                                _userprofile.AttachCV = _uploadFilePath;
                                _userprofile.Status = "Complete";
                                _userprofile.RefUserId = _useraccount.UID;

                                if (Session["ConfirmLastFileName"] != null)
                                {
                                    string _tempFilePath = Session["ConfirmLastFileName"].ToString();
                                    Session["ConfirmLastFileName"] = null;

                                    string _webUrl = string.Empty;
                                    string _filePath = GetFilePath(out _webUrl);
                                    string _guidString = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 8);
                                    string _fileName = "Voice_user" + _useraccount.UID.ToString() + "_" + _guidString + ".wav";

                                    string fileName = _filePath + _fileName;

                                    if (System.IO.File.Exists(fileName))
                                    {
                                        System.IO.File.Delete(fileName);
                                    }
                                    System.IO.File.Move(_tempFilePath, fileName);

                                    _userprofile.VoiceRecord = fileName;
                                }

                                _result = _userprofiledb.Insert(_userprofile);

                                if (_result > 0)
                                {
                                    if (_jid > 0)
                                    {
                                        _application.Comments = Server.HtmlEncode(txtSummary.Text);
                                        _application.RefUserID = _useraccount.UID;
                                        _application.RefJobID = _jid;
                                        _application.ApplicationStatus = "pending";
                                        _result = _applicationdb.InsertUpdate(_application);
                                    }
                                }
                            }

                            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                            var random = new Random();
                            var result = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray());
                            string salt = CE.Security.MySecurity.Encrypt(result, true);
                            string strGUID = _useraccountdb.GetGUID(_useraccount.UID);
                            salt = salt.Replace("+", "");
                            _useraccount.AuthSalt = salt;
                            _result = _useraccountdb.Insert(_useraccount);
                            if (_result > 0)
                            {
                                bool _mailresult = MyMailManager.SendNewUserActivateLink(_useraccount.Email, _useraccount.Email, _useraccount.AuthSalt, strGUID, _useraccount.AuthCode, CE.Global.CEUserType.Customer);
                                if (_mailresult)
                                {
                                    Response.Redirect("job-submit.aspx?say=thankyou");
                                }
                                else
                                {
                                    divMessage.Visible = true;
                                    lblMessage.Text = "Error found! Failed to send message.<br/>Pleas try again it later.";
                                    lblMessage.Font.Bold = true;
                                    lblMessage.ForeColor = System.Drawing.Color.Red;
                                }
                            }

                            ////System.Threading.Thread.Sleep(5000);
                            //string _bccEmail = string.Empty;
                            //MailClient _remail = new MailClient();
                            //string _toEmail = System.Configuration.ConfigurationSettings.AppSettings["TDS.JobAppEmailReceiver"].ToString();

                            //if (lblJobRefCode.Text.StartsWith("MY"))
                            //{
                            //    _toEmail = System.Configuration.ConfigurationSettings.AppSettings["TDM.JobAppEmailReceiver"].ToString();
                            //    _bccEmail = "roy.ebiz@gmail.com;";
                            //}
                            //else if (lblJobRefCode.Text.StartsWith("SG"))
                            //{
                            //    _toEmail = System.Configuration.ConfigurationSettings.AppSettings["TDS.JobAppEmailReceiverTwo"].ToString();
                            //}

                            //string _strCVFileName = fupCV.FileName;
                            //string _strTitle = "Online Job Application Form (" + ddlTitle.SelectedItem.Text + " " + txtFullName.Text + ") at Date/Time:" + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");

                            //if (lblJobRefCode.Text.Length > 0)
                            //{
                            //    _strTitle = lblFormSubTitle.Text + "(" + ddlTitle.SelectedItem.Text + " " + txtFullName.Text + ") at Date/Time:" + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt");
                            //}

                            //System.Text.StringBuilder _strBody = new System.Text.StringBuilder();
                            //_strBody.Append("Dear Sir/Madam,<br/><br/>");
                            //if (spanCV.Visible && spanFCV.Visible)
                            //{
                            //    _strBody.Append("Please check following details and find enclosed CV file.<br/><br/>");
                            //}
                            //else
                            //{
                            //    _strBody.Append("Please check following details.");
                            //}
                            //_strBody.Append("<table style=\"width:80%;\" cellspacing=\"5\" cellpadding=\"5\">");
                            //if (lblJobRefCode.Text.Length > 0)
                            //{
                            //    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Job Title</td><td valign=\"top\">:</td><td><b>" + lblFormSubTitle.Text + "</b></td></tr>");
                            //    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Job Ref. Code</td><td valign=\"top\">:</td><td><b>" + lblJobRefCode.Text + "</b></td></tr>");
                            //}

                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Full Name</td><td valign=\"top\">:</td><td>" + ddlTitle.SelectedItem.Text + " " + Server.HtmlEncode(txtFullName.Text) + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\">Email Address</td><td>:</td><td>" + txtEmailAddress.Text + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Contact Number</td><td valign=\"top\">:</td><td>" + Server.HtmlEncode(txtContactNumber.Text.Trim()) + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Age</td><td valign=\"top\">:</td><td>" + txtAge.Text + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Qualification</td><td valign=\"top\">:</td><td>" + Server.HtmlEncode(txtQualification.Text.Trim()) + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">No of Years of Experience</td><td valign=\"top\">:</td><td>" + ddlExpYear.SelectedItem.Text + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Sales Experience</td><td valign=\"top\">:</td><td>" + ddlSaleExp.SelectedItem.Text + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Employment Status</td><td valign=\"top\">:</td><td>" + ddlEmpStatus.SelectedItem.Text + "</td></tr>");
                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Preferred Country</td><td valign=\"top\">:</td><td>" + ddlCountry.SelectedItem.Text + "</td></tr>");

                            ////if (spanCV.Visible && spanFCV.Visible && fupCV.HasFile)
                            ////{
                            ////    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Original File Name</td><td valign=\"top\">:</td><td>" + fupCV.FileName + "</td></tr>");
                            ////}
                            ////else
                            ////{
                            ////    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Summary</td><td valign=\"top\">:</td><td>" + Server.HtmlEncode(txtSummary.Text.Trim()).Replace("\r\n", "<br/>") + "</td></tr>");
                            ////}

                            //_strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Original File Name</td><td valign=\"top\">:</td><td>" + fupCV.FileName + "</td></tr>");
                            //if (txtSummary.Text.Trim().Length > 0)
                            //{
                            //    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Comments</td><td valign=\"top\">:</td><td>" + Server.HtmlEncode(txtSummary.Text.Trim()).Replace("\r\n", "<br/>") + "</td></tr>");
                            //}
                            //else
                            //{
                            //    _strBody.Append("<tr><td style=\"width:180px;\" valign=\"top\">Comments</td><td valign=\"top\">:</td><td>No comments.</td></tr>");
                            //}

                            //_strBody.Append("</table>");

                            //string _uploadFilePath = string.Empty;

                            //if (spanCV.Visible && spanFCV.Visible && UploadFile(out _uploadFilePath))
                            //{
                            //    string[] fileList = new string[1];
                            //    if (_uploadFilePath != string.Empty)
                            //    {
                            //        fileList[0] = _uploadFilePath;
                            //    }

                            //    if (_remail.SendNetNoreplyMailByAttachements(_strTitle, _strBody.ToString(), "Teledirect Online Job Application", "Teledirect HR", _toEmail, string.Empty, _bccEmail, fileList))
                            //    {
                            //        Response.Redirect("submit.aspx?say=thankyou");
                            //    }
                            //    else
                            //    {
                            //        divMessage.Visible = true;
                            //        lblMessage.Text = "Error found! Failed to send message.<br/>Pleas try again it later.";
                            //        lblMessage.Font.Bold = true;
                            //        lblMessage.ForeColor = System.Drawing.Color.Red;
                            //    }
                            //}
                            //else
                            //{
                            //    if (_remail.SendNetNoreplyMail(_strTitle, _strBody.ToString(), "Teledirect Online Job Application", "Teledirect HR", _toEmail, string.Empty, _bccEmail))
                            //    {
                            //        Response.Redirect("submit.aspx?say=thankyou");
                            //    }
                            //    else
                            //    {
                            //        divMessage.Visible = true;
                            //        lblMessage.Text = "Error found! Failed to send message.<br/>Pleas try again it later.";
                            //        lblMessage.Font.Bold = true;
                            //        lblMessage.ForeColor = System.Drawing.Color.Red;
                            //    }
                            //}
                        }
                        else
                        {
                            divMessage.Visible = true;
                            lblMessage.Text = "Wrong security check code. Please try again!";
                            lblMessage.Font.Bold = true;
                            lblMessage.ForeColor = System.Drawing.Color.Red;

                            Session[GlobalSettings.CaptchaImageText] = GlobalSettings.GenerateRandomCode(4);
                            hidSecurityCheck.Value = Session[GlobalSettings.CaptchaImageText].ToString();
                            //lblMessage.Text = "Encrypt:" + hidSecurityCheck.Value.ToString() + ", Decrypt:" + MOC.Utilities.Security.MySecurity.Decrypt(hidSecurityCheck.Value.ToString(), true);
                        }

                    }
                    catch (Exception Ex)
                    {
                        divMessage.Visible = true;
                        lblMessage.Text = "Error found! Please try it later again.<br/>" + Ex.Message;
                        lblMessage.Font.Bold = true;
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
    }

    private bool UploadFile(out string filePath, Int64 uid)
    {
        bool _retValue = false;

        filePath = string.Empty;

        try
        {
            TDS.IO.FileSystem _newFile = new TDS.IO.FileSystem();
            if (fupCV.HasFile)
            {
                HttpPostedFile _postFile = fupCV.PostedFile;

                int _fileLen = 0;

                if (_postFile.ContentLength > 0)
                {
                    _fileLen = _postFile.ContentLength / 1024;
                }

                string _fileName = _postFile.FileName;
                string _fileExt = System.IO.Path.GetExtension(_fileName).ToLower();
                bool _fileExtValid = false;

                string[] _arrFileExt = System.Configuration.ConfigurationManager.AppSettings["TDSJ.CVUploadFileExt"].Split(',');
                int _fileSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TDSJ.CVUploadFileSizeKB"]);

                for (int i = 0; i < _arrFileExt.Length; i++)
                {
                    if (_fileExt == _arrFileExt[i])
                    {
                        _fileExtValid = true;
                        break;
                    }
                }

                if (_fileExtValid)
                {
                    if (_fileLen > 0 && _fileLen <= _fileSize)
                    {
                        //string _filePath = AppDomain.CurrentDomain.BaseDirectory + "TDSCVUploadFiles\\";
                        string _filePath = AppDomain.CurrentDomain.BaseDirectory + "user\\";
                        //string _filePath = System.Configuration.ConfigurationManager.AppSettings["TDSJ.CVUploadFilePath"];
                        if (_newFile.CheckDirectory(_filePath))
                        {
                            //string _curMonth = DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00");

                            //if (!_newFile.CheckDirectory(_filePath + _curMonth))
                            //{
                            //    if (_newFile.CreateDirectory(_filePath, _curMonth))
                            //    {
                            //        _filePath += _curMonth + "\\";
                            //    }
                            //}
                            //else
                            //{
                            //    _filePath += _curMonth + "\\";
                            //}

                            //string _curDate = DateTime.Now.ToString("ddMMMyyyy");

                            //if (!_newFile.CheckDirectory(_filePath + _curDate))
                            //{
                            //    if (_newFile.CreateDirectory(_filePath, _curDate))
                            //    {
                            //        _filePath += _curDate + "\\";
                            //    }
                            //}
                            //else
                            //{
                            //    _filePath += _curDate + "\\";
                            //}

                            //filePath = _filePath + "JobApp_" + DateTime.Now.ToString("ddMMMyyyy_hhmmss_tt") + _fileExt;

                            //fupCV.SaveAs(filePath);

                            //_retValue = true;
                            ////_newFile.WriteNewFile(_filePath, _fileName, strException);
                            //_newFile = null;

                            string _curResumePath = "resume";

                            if (!_newFile.CheckDirectory(_filePath + _curResumePath))
                            {
                                if (_newFile.CreateDirectory(_filePath, _curResumePath))
                                {
                                    _filePath += _curResumePath + "\\";
                                }
                            }
                            else
                            {
                                _filePath += _curResumePath + "\\";
                            }

                            filePath = _filePath + "CV_" + uid.ToString() + "_" + DateTime.Now.ToString("ddMMMyyyy_hhmmss_tt") + _fileExt;

                            fupCV.SaveAs(filePath);

                            _retValue = true;
                            //_newFile.WriteNewFile(_filePath, _fileName, strException);
                            _newFile = null;
                        }
                    }
                    else
                    {
                        lblUploadMessage.Text = "<br/>Invalid or File size is over limit.";
                    }
                }
                else
                {
                    lblUploadMessage.Text = "<br/>Invalid file type.";
                }
            }
            //else
            //{
            //    //Mobile Device
            //    _retValue = !rfvCV.Enabled;
            //}
        }
        catch (Exception Ex)
        {
            lblUploadMessage.Text = "<br/>" + Ex.Message;
        }

        return _retValue;
    }
    private string GetFilePath(out string webUrl)
    {
        string _filePath = Server.MapPath("~\\voice-recording\\upload\\");
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
        webUrl = "~/voice-recording/upload/";

        string _file = "Store";
        if (!_myIO.CheckDirectory(_filePath + _file))
        {
            if (_myIO.CreateDirectory(_filePath, _file))
            {
                _filePath += _file + "\\";
                webUrl += _file + "/";
            }
        }
        else
        {
            _filePath += _file + "\\";
            webUrl += _file + "/";
        }

        return _filePath;
    }
}
